import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import refresh from '@feidao/web/atom/browser/url/refresh';
export default async function ca018(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	// ç¡®å®š æ•°å€¼
	const key = args[0].target.dataset.feidaoId;
	const begin_input_id = 'min_' + key;
	const end_input_id = 'max_' + key;
	const query = fd.data.params;
	delete query['page-no'];
	// const q = (query.param || (query.param = {}));
	const param = query.param && JSON.parse(query.param);
	const q = param ? param : {};
	const check_input = fd.data.node.querySelector('[data-feidao-id=check_' + key + ']') as HTMLInputElement;
	if (check_input.checked) {
		query.param = JSON.stringify(q);
		refresh(query);
	} else {
		const begin = fd.data.node.querySelector('[data-feidao-id=' + begin_input_id + ']') as HTMLInputElement;
		const end = fd.data.node.querySelector('[data-feidao-id=' + end_input_id + ']') as HTMLInputElement;
		const b_value = (() => {
			if (begin.value) {
				return begin.valueAsNumber;
			} else {
				return 0;
			}
		})();
		const e_value = (() => {
			if (end.value) {
				return end.valueAsNumber;
			} else {
				return 0;
			}
		})();
		const url_put = (() => {
			if (b_value && e_value) {
				return [b_value, e_value];
			} else if (b_value) {
				return [b_value];
			} else if (e_value) {
				return [null, e_value];
			}
		})();
		if (url_put) {
			q[key] = url_put;
			query.param = JSON.stringify(q);
			refresh(query);
		}
	}
}
